import numpy as np

def hist(data):
    ''' calculate histogram and return in format
        (neg_bincount, neg_bins, pos_bincount, pos_bins)
    '''

    output = list()

    # split neg and positive
    pos = data[np.where(data >= 0)]
    neg = -data[np.where(data < 0)]

    neg_c, pos_c = np.bincount(neg), np.bincount(pos)
    neg_b, pos_b = - np.array(range(len(neg_c))), np.array(range(len(pos_c)))
    neg_b = neg_b[1:]
    neg_c = neg_c[1:]
    return neg_c, neg_b, pos_c, pos_b
    
    ''' dict method 5 minutes
    output = dict()
    tm = timer(0, len(data))
    i = 0
    print 'starting'
    for d in data:
        i += 1
        tm.progress(i)
        try:
            output[d] += 1
        except:
            output[d] = 1
    print 'dict', tm.elapsed()
    '''

if __name__ == '__main__':
    print 'test hist'
    print 'a'
    a = np.array([-5, -2, -2, -1, 0, 1, 2, 3])
    print a
    nc, nb, pc, pb = hist(a)
    print 'neg'
    print nb, nc
    print 'pos'
    print pb, pc
